package view.plugin
{
	//参赛界面
	
	import fl.containers.ScrollPane;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import flash3.framework.Singleton;
	
	import global.Resource;
	
	import model.GameModel;
	
	import vo.MoneyPoolItem;
	
	public class RallyPanel extends PanelBase
	{
		public var btnStart:SimpleButton;
		public var btnReturn:SimpleButton;
		public var desc:DisplayObject;
		public var item:Array;
		public var panel:ScrollPane;
		public var gold:TextField;
		
		public static var STARTGAME:String = "startgame";
		public static var CANSEL:String = "cansel";
		
		public function RallyPanel()
		{
			super();
			var main:MovieClip = Resource.i.getMovieClip("dlgRally", "DlgRally");
			addChild(main);
			btnStart = main.btnStart;
			btnReturn = main.btnReturn;
			desc = main.desc;
			gold = main.gold;
			item = [main.item1,main.item2,main.item3];
			btnStart.addEventListener(MouseEvent.CLICK, onClickBtnStart);
			btnReturn.addEventListener(MouseEvent.CLICK, onClickBtnReturn);
			panel = new ScrollPane();
			panel.source = desc;
			panel.move(26, 325);
			panel.setSize(511, 166);
			panel.update();
			main.addChild(panel);
		}
		override public function show(v:Boolean):void
		{
			super.show(v);
			if(v)this.y = 100;
		}
		private function onClickBtnStart(evt:MouseEvent):void
		{
			show(false);
			this.dispatchEvent(new Event(STARTGAME));
		}
		
		private function onClickBtnReturn(evt:MouseEvent):void
		{
			show(false);
			this.dispatchEvent(new Event(CANSEL));
		}
		
		public function updateData():void
		{
			panel.verticalScrollBar.scrollPosition = panel.verticalScrollBar.minScrollPosition;
			gold.text = GameModel.i.gameServer.dwEnterFee.toString();
			var frame:uint = 0;
			switch(GameModel.i.gameServer.dwEnterFee)
			{
				case 10: frame = 1; break;
				case 100: frame = 2; break;
				case 1000: frame = 3; break;
				case 10000: frame = 4; break;
			}
			(desc as MovieClip).gotoAndStop(frame);
			var poolItem:MoneyPoolItem = GameModel.i.poolItem;
			for(var i:uint = 0; i < item.length; i++)
			{
				if(item[i] && poolItem.listPoolItem[i])
				{
					item[i].visible = true;
					item[i].awardName.text = poolItem.listPoolItem[i].name;
					item[i].time.text = poolItem.listPoolItem[i].time == 0 ? "实时" : ("每"+poolItem.listPoolItem[i].time+"分钟");
					item[i].by.text   = poolItem.listPoolItem[i].by;
					item[i].gold.text = poolItem.listPoolItem[i].gold;
				}
				else
				{
					item[i].visible = false;
				}
			}
		}
		
		static public function get i():RallyPanel
		{
			return Singleton.getInstanceOrCreate(RallyPanel) as RallyPanel;
		}
	}
}